﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;
using MVC_Project.Model;

namespace MVC_Project.Dal
{
    public class DbContextFactory
    {
        public static DbContext Create() {

            //在容器中获取数据上下文
            var dbcontext = CallContext.GetData("dbcontext");
            if (dbcontext==null)
            {
                dbcontext = new Entities();
                //在容器中保存数据上下文
                CallContext.SetData("dbcontext", dbcontext);
                
            }
            return dbcontext as DbContext;
        }
    }
}
